package com.bawei.mvp.view;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bawei.mvp.presenter.IPresenter;
import com.blankj.utilcode.util.ToastUtils;


public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IFragment, IView {

    protected P mPresenter;
    private View baseView;
    protected FrameLayout groupView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        groupView = new FrameLayout(getContext());

        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        groupView.setLayoutParams(params);
        groupView.addView(baseView = inflater.inflate(bandLayout(), container, false));
        return groupView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initData();
    }

    @Override
    public <V extends View> V findViewById(int id) {
        return baseView.findViewById(id);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showToast(String msg) {
        ToastUtils.showShort(msg);
    }


    @Override
    public void showAlert() {

    }



    @Override
    public void hideErrorView() {

    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mPresenter != null) {
            mPresenter.destroy();
            mPresenter = null;
        }
    }
}
